package com.yx.study.leet.questionList.questions;

import java.util.Arrays;

/**
 * @Classname findMedianSortedArrays04
 * @Date 2022/06/29 13:22
 * @Author by yx
 * @Description : 4. 寻找两个正序数组的中位数 https://leetcode.cn/problems/median-of-two-sorted-arrays/
 */
public class findMedianSortedArrays04 {
    public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int length1 = nums1.length;
        int length2 = nums2.length;
        int median = (length1 + length2)/2;
        int[] nums = new int[length1+length2];
        System.arraycopy(nums1, 0, nums, 0, length1);
        System.arraycopy(nums2, 0, nums, length1, length2);
        Arrays.sort(nums);
        return (length1+length2)%2==0?(nums[median]+nums[median-1])/2.0:nums[median];
    }

    public static void main(String[] args) {
        int[] ints = {1, 2};
        int[] ints2 = {3,4};
        double medianSortedArrays = findMedianSortedArrays(ints,ints2);
        System.out.println(medianSortedArrays);
    }
}
